package cn.tianya.irock.bll;

//import org.apache.log4j.Logger;

import cn.tianya.fw.service.ComponentClientService;
import cn.tianya.fw.service.ServiceFactory;
import cn.tianya.irock.data.model.PointInfo;
import cn.tianya.irock.enums.SystemExceptionType;
import cn.tianya.irock.exceptions.SystemException;
import cn.tianya.score.component.ScoreInterfPrx;

public class Points {
	private static ScoreInterfPrx proxy;
	private static ComponentClientService client;
	
	static {
		client = ServiceFactory.newInstance("score_service").getComponentClientService();
		proxy = client.getProxy(ScoreInterfPrx.class);
	}
	
	public static int getScore(String strwriter,String idwriter){ //
		return proxy.getScoreById(idwriter);
	}
	
	public static int getScoreOld(int idwriter){ //
		int getScoreOld = 0;
		try{
			getScoreOld = proxy.getScore(idwriter);
		}catch(Exception ex){
			throw new SystemException(SystemExceptionType.APIError, "ICE score_service:" + ex.getMessage());
		}
		return getScoreOld;
	}
	
	public static void setScore(String idwriter, String strwriter, PointInfo scoreRule, int score) {
		try {
			proxy.saveScore(getParaToXml(idwriter,strwriter,scoreRule,score));
			//<?xml version="1.0" encoding="utf-8" ?><dataset><row><code><![CDATA[1]]></code></row></dataset>
			//if(result!=null && result.indexOf("CDATA[1]")>0){
			//	setScore=true;
			//}
		} catch (Exception ex) {
			throw new SystemException(SystemExceptionType.APIError, "ICE score_service:" + ex.getMessage());
		}
	}
	
	private static String getParaToXml(String idwriter, String strwriter, PointInfo scoreRule, int score) {
		return "<?xml version=\"1.0\" encoding=\"utf-8\" ?><dataset><row><userId><![CDATA["+idwriter+"]]></userId><userName><![CDATA["+strwriter+"]]></userName><bizId><![CDATA["+scoreRule.getBizId()+"]]></bizId><actionCode><![CDATA["+scoreRule.getActionCode()+"]]></actionCode><actionDesc><![CDATA["+scoreRule.getActionDesc()+"]]></actionDesc><score><![CDATA["+score+"]]></score></row></dataset>";
	}
}
